# 税务PDF数据提取系统 Makefile

.PHONY: setup run test clean docker docker-run docker-stop

# 默认目标
all: setup

# 设置环境
setup:
	@echo "设置开发环境..."
	@python -m venv venv || echo "创建虚拟环境失败"
	@. venv/bin/activate && pip install -r requirements.txt || echo "安装依赖失败"
	@mkdir -p logs uploads static
	@echo "环境设置完成"

# 运行应用
run:
	@echo "启动应用..."
	@. venv/bin/activate && python run.py

# 运行测试
test:
	@echo "运行测试..."
	@. venv/bin/activate && pytest -v

# 运行测试并生成覆盖率报告
coverage:
	@echo "运行测试覆盖率..."
	@. venv/bin/activate && pytest --cov=app tests/ --cov-report=term --cov-report=html
	@echo "覆盖率报告已生成在 htmlcov/ 目录"

# 清理临时文件
clean:
	@echo "清理临时文件..."
	@rm -rf __pycache__ .pytest_cache .coverage htmlcov
	@find . -type d -name __pycache__ -exec rm -rf {} +
	@find . -type f -name "*.pyc" -delete
	@echo "清理完成"

# 构建Docker镜像
docker:
	@echo "构建Docker镜像..."
	@docker build -t tax-pdf-extractor .

# 运行Docker容器
docker-run:
	@echo "启动Docker容器..."
	@docker-compose up -d

# 停止Docker容器
docker-stop:
	@echo "停止Docker容器..."
	@docker-compose down

# 帮助信息
help:
	@echo "税务PDF数据提取系统 - 可用命令:"
	@echo "  make setup      - 设置开发环境"
	@echo "  make run        - 运行应用"
	@echo "  make test       - 运行测试"
	@echo "  make coverage   - 运行测试覆盖率"
	@echo "  make clean      - 清理临时文件"
	@echo "  make docker     - 构建Docker镜像"
	@echo "  make docker-run - 启动Docker容器"
	@echo "  make docker-stop- 停止Docker容器"
	@echo "  make help       - 显示帮助信息"